<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class CreateOrderRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'roomId' => 'required|string',
            'dishes' => 'required|array|min:1',
            'dishes.*.dishId' => 'required|exists:dishes,id',
            'dishes.*.quantity' => 'required|integer|min:1|max:10',
            'dishes.*.flavor' => 'sometimes|string|max:50',
            'dishes.*.note' => 'sometimes|string|max:255',
        ];
    }

    /**
     * Get custom messages for validator errors.
     */
    public function messages(): array
    {
        return [
            'roomId.required' => '房间ID不能为空',
            'dishes.required' => '菜品列表不能为空',
            'dishes.min' => '至少需要选择一个菜品',
            'dishes.*.dishId.required' => '菜品ID不能为空',
            'dishes.*.dishId.exists' => '菜品不存在',
            'dishes.*.quantity.required' => '菜品数量不能为空',
            'dishes.*.quantity.integer' => '菜品数量必须是整数',
            'dishes.*.quantity.min' => '菜品数量至少为1',
            'dishes.*.quantity.max' => '菜品数量不能超过10',
            'dishes.*.flavor.max' => '口味描述不能超过50个字符',
            'dishes.*.note.max' => '备注不能超过255个字符',
        ];
    }
}
